package com.echartsdata.security;

import com.echartsdata.Entityimp.Userimp;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
//验证用户
@Service
public class JwtUserDetailsService implements UserDetailsService {
    @Resource
    private Userimp userimp;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        com.echartsdata.Entity.User uu = userimp.get_user(username);
        if (uu!=null) {
            return new User(uu.getUsername(), uu.getPassword(),
                    new ArrayList<>());
        } else {
            throw new UsernameNotFoundException("未找到用户名对应的用户: " + username);
        }
    }
}
